package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 刘付磊
 * @date 2021/11/15 0015
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;



    //查询今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }
    /*查询分页的好友列表*/
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult pr= tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }
    /*查看佳人详情*/
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId ){
        TodayBest vo = tanhuaService.personalInfo(userId);


        return ResponseEntity.ok(vo);
    }
    /*查看陌生人问题*/
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }
    @PostMapping("/strangerQuestions")
    public ResponseEntity replystrangerQuestions(@RequestBody Map map){
        //前端传递的userid是integer类型
        String userId = map.get("userId").toString();
        Long aLong = Long.valueOf(userId);
        String reply = map.get("reply").toString();
        tanhuaService.replystrangerQuestions(aLong,reply);
        return ResponseEntity.ok(null);
    }
    @GetMapping("cards")
    public ResponseEntity cards(){
        List<TodayBest> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId){
        tanhuaService.love(likeUserId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId){
        tanhuaService.unlove(likeUserId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,@RequestParam(defaultValue = "2000") String distance){

        List<NearUserVo> list= tanhuaService.queryNearUser(gender,distance);

        return ResponseEntity.ok(list);
    }
}
